import pandas as pd
from datetime import timedelta
tick_data = pd.read_csv("D:\\learn_and_test_data\\tick聚合\\PRT c2005-P-2120&c2005_20200116.csv")
print(tick_data.shape[0])
if tick_data.empty:
    print("empty")
tick_data["date"] = tick_data["TradingDay"].astype("str")
tick_data["datetime"] = tick_data["date"] + " " + tick_data["UpdateTime"].str.slice(0, -3)
tick_data["datetime"] = pd.to_datetime(tick_data["datetime"], format="%Y%m%d %H:%M")
time_group = tick_data.groupby("datetime")

bar_data = time_group["AskPrice1"].ohlc()
hour_range = [9, 10, 11, 12, 13, 14, 15, 21, 22, 23, 0, 1, 2]
hour = bar_data.index.hour
bar_data = bar_data.loc[hour.isin(hour_range)]
bar_data.index += timedelta(seconds=60)
print(bar_data)
#bar_data.to_csv("D:\\learn_and_test_data\\tick聚合\\bar_data.csv")
